define(function(require,exports,module){
	var Subnav = require("subnav");
	var aw = require("ajaxwrapper");
	var store = require("store");
	var activeUser = store.get("user");
	var enmu = require("enums");
	var roomPanoramaHandler = require("../handler/roomPanoramaHandler");
	var handler = require("../handler/ScatterCheckInHandler");
	var fetchProperties = require("../constant/fetchProperties");
	
	module.exports = {
		initComponent: function(params,widget){
			var subnav = new Subnav({
				parentNode: ".J-subnav",
				model: {
					title: "散客入住登记",
					items: [{
						id:"search",
						type: "search",
						placeholder: "联系人/联系电话",
						handler: function(str){
							aw.ajax({
								url: "api/checkinimplement/search",
								data: {
									s: str,
									properties: "nonMemGroupReserve.nonMemberGroup.contactName,nonMemGroupReserve.nonMemberGroup.contactPhone",
									fetchProperties: fetchProperties.fetchProperties
								},
								success: function(data){
									widget.get("grid").setData(data);
								}
							});
						}
					},{
						id : "servicePoint",
						text : "服务点",
						tip : "服务点",
//						url:"api/servicepoint/operableservicepoints",
//						lazy:true,
						items:activeUser.privateServicePoints,
						type : "buttongroup",
						keyField : "pkServicePoint",
						valueField : "name",
						all: {
							show: true,
							position: "bottom"
						},
						handler:function(key,element){	
							widget.queryByStatus(widget);
						}
					},{
        				id: "registerStatus",
        				tip:"状态",
        				type:"buttongroup",
        				items:enmu["com.eling.elcms.travel.model.CheckIn.Status"],
        				handler: function(){
        					widget.queryByStatus(widget);
        				}
        			},{
			            id: "dateRange",
			            type: "daterange",
			            tip:"入住日期",
			            ranges: {
			                "今天": [moment().startOf("days"), moment().endOf("days")],
			                "本月": [moment().startOf("month"), moment().endOf("month")]
			            },
			            defaultRange: "本月",
			            minDate: "1930-05-31",
			            maxDate: "2020-12-31",
			            handler: function(time) {
			            	widget.queryByStatus(widget);
			            }
			        },{
			        	id:"visit",
			        	text:"上门登记",
			        	type:"button",
			        	handler:function(){
			        		handler.subnav.handleVisitClick(widget);
			        	}
			        },{
			        	id:"save",
			        	text:"保存",
			        	type:"button",
			        	show : false,
			        	handler:function(){			        		
			        		handler.subnav.handleSaveClick(widget);			        		
			        	}
			        },{
						id:"return",
						type:"button",
						text:"返回",
						show : false,
						handler:function(){
							widget.toGrid();
						}
					},{
						id : "building",
						text : "楼宇",
						tip : "楼宇",
						lazy:true,
						type : "buttongroup",
						keyField: "pkOrgBuilding",
        	            valueField: "name",
        	            url:"api/orgbuilding/getuserorgbuilding",
						handler:function(key,element){	
							subnav.load("roomType", {
		        				params:{
		        					orgBuilding: subnav.getValue("building"),
		        	            	fetchProperties:"pkRoomType,name"
		        	            },
		                        callback: function(data) {
		                            subnav.setData("roomType", data);
		                            roomPanoramaHandler.setData(widget.get("curStatus"),widget);
		                        }
		                    });
						}
					},{
						id : "roomType",
						text : "房型",
						tip : "房型",
						lazy:true,
						type : "buttongroup",
						keyField: "pkRoomType",
        	            valueField: "name",
        	            url:"api/groupreserve/queryroomtype",
						handler:function(key,element){	
							roomPanoramaHandler.setData(widget.get("curStatus"),widget);
						}
					},{
						id:"roomStateReturn",
						type:"button",
						text:"取消",
						show : false,
						handler:function(){
							widget.roomStateReturnClick(widget.get("showForm"),widget.get("hideForm"));
						}
					},{
						id:"roomStateConfirm",
						type:"button",
						text:"确认",
						show : false,
						handler:function(){
							widget.roomStateConfirm();
						}
					}]
				}
			});
			
			widget.set("subnav",subnav);
		}
	};
});